/* Copyright(c) 2010- Siro-info Co.(http://www.siro-info.com)
 * All rights reserved.
 */
package com.siro.pm.model.provider;

import java.util.List;

import com.siro.pm.I18nManager;
import com.siro.pm.model.Developer;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;

/**
 * Class Declaration:
 * 
 * @version v1.0
 * @since DeveloperProvider.java v1.0
 */
public class DeveloperProvider {
	public static String DEVELOPER_PROPERTY_NAME = I18nManager
			.getMessage("developer.name");
	public static String DEVELOPER_PROPERTY_PASSWORD = I18nManager
			.getMessage("developer.password");
	public static String DEVELOPER_PROPERTY_ROLE = I18nManager
			.getMessage("developer.role");
	public static String DEVELOPER_PROPERTY_POSTNAME = I18nManager
			.getMessage("developer.postName");
	public static String DEVELOPER_PROPERTY_PHONENUM = I18nManager
			.getMessage("developer.phoneNum");
	public static String DEVELOPER_PROPERTY_MAILADDR = I18nManager
			.getMessage("developer.mailAddr");
	public static String DEVELOPER_PROPERTY_ORGNAME = I18nManager
			.getMessage("developer.orgName");

	public static final String[] DEVELOPER_ROLE_DATA = {
			I18nManager.getMessage("developer.role.normal"),
			I18nManager.getMessage("developer.role.manager"), };

	static IndexedContainer developersContainer;
	static {
		developersContainer = new IndexedContainer();
		developersContainer.addContainerProperty(DEVELOPER_PROPERTY_NAME,
				String.class, "");
		// developersContainer.addContainerProperty(DEVELOPER_PROPERTY_PASSWORD,
		// String.class, "");
		developersContainer.addContainerProperty(DEVELOPER_PROPERTY_ROLE,
				String.class, "");
		developersContainer.addContainerProperty(DEVELOPER_PROPERTY_POSTNAME,
				String.class, "");
		developersContainer.addContainerProperty(DEVELOPER_PROPERTY_PHONENUM,
				String.class, "");
		developersContainer.addContainerProperty(DEVELOPER_PROPERTY_MAILADDR,
				String.class, "");
		developersContainer.addContainerProperty(DEVELOPER_PROPERTY_ORGNAME,
				String.class, "");
	}

	public static IndexedContainer getDevelopersData(List<Developer> developers) {
		developersContainer.removeAllItems();
		if (developers == null) {
			developers = Developer.getAllDevelopers();
		}
		for (Developer developer : developers) {
			Item item = developersContainer.addItem(developer);
			item.getItemProperty(DEVELOPER_PROPERTY_NAME).setValue(
					developer.getName());
			// item.getItemProperty(DEVELOPER_PROPERTY_PASSWORD).setValue(
			// developer.getPassword());
			item.getItemProperty(DEVELOPER_PROPERTY_ROLE).setValue(
					developer.getRole());
			item.getItemProperty(DEVELOPER_PROPERTY_POSTNAME).setValue(
					developer.getPostName());
			item.getItemProperty(DEVELOPER_PROPERTY_PHONENUM).setValue(
					developer.getPhoneNum());
			item.getItemProperty(DEVELOPER_PROPERTY_MAILADDR).setValue(
					developer.getMailAddr());
			item.getItemProperty(DEVELOPER_PROPERTY_ORGNAME).setValue(
					developer.getOrgName());
		}

		return developersContainer;
	}

}
